<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomer extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('customer')) {
            return;
        }
        Schema::create('customer', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('parent_id')->default(0)->comment('父级ID');
            $table->string('customer_number', 64)->default('')->unique()->comment('客户单位编号');
            $table->string('name', 64)->default('')->comment('客户单位名称');
            $table->string('short_name', 64)->default('')->comment('客户简介');
            $table->string('customer_type_name', 64)->default('')->comment('单位类型名称');
            $table->string('entry_type_name', 64)->default('')->comment('客户类型');
            $table->string('tag_name', 64)->default('')->comment('客户标签');
            $table->string('industry_name', 64)->default('')->comment('客户所在行业');
            $table->string('safe_level', 64)->default('')->comment('安全等级');
            $table->string('source', 64)->default('')->comment('客户来源');
            $table->unsignedInteger('department_id')->default(0)->comment('服务部门ID');
            $table->string('department_name', 64)->default('')->unique()->comment('服务部门名称');
            $table->unsignedInteger('owner_id')->default(0)->comment('负责人ID');
            $table->string('owner_name', 64)->default('')->unique()->comment('负责人姓名');
            $table->unsignedInteger('country_id')->default(0)->comment('国家ID');
            $table->string('country_name', 64)->default('')->comment('国家名称');
            $table->unsignedInteger('province_id')->default(0)->comment('省份ID');
            $table->string('province_name', 64)->default('')->comment('省份名称');
            $table->unsignedInteger('city_id')->default(0)->comment('城市ID');
            $table->string('city_name', 64)->default('')->comment('城市名称');
            $table->unsignedInteger('county_id')->default(0)->comment('区县ID');
            $table->string('county_name', 64)->default('')->comment('区县名称');
            $table->string('address', 255)->default('')->comment('详细地址');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });

        Schema::create('customer_user', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 64)->default('')->unique()->comment('姓名');
            $table->string('gender')->default('')->comment('性别');
            $table->string('phone', 32)->default('')->comment('联系电话');
            $table->string('office_phone', 32)->default('')->comment('办公电话');
            $table->string('email', 32)->default('')->comment('电子邮箱');
            $table->string('birthday', 32)->default('')->comment('出生日期');
            $table->string('duty', 255)->default('')->comment('职务');
            $table->string('project_role', 255)->default('')->comment('项目角色');
            $table->unsignedInteger('customer_id')->default(0)->comment('客户单位ID');
            $table->string('customer_name', 64)->default('')->comment('客户单位名称');
            $table->unsignedInteger('country_id')->default(0)->comment('国家ID');
            $table->string('country_name', 64)->default('')->comment('国家名称');
            $table->unsignedInteger('province_id')->default(0)->comment('省份ID');
            $table->string('province_name', 64)->default('')->comment('省份名称');
            $table->unsignedInteger('city_id')->default(0)->comment('城市ID');
            $table->string('city_name', 64)->default('')->comment('城市名称');
            $table->unsignedInteger('county_id')->default(0)->comment('区县ID');
            $table->string('county_name', 64)->default('')->comment('区县名称');
            $table->string('address', 255)->default('')->comment('详细地址');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态');
            $table->unsignedInteger('create_user_id')->default(0)->comment('操作人ID');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customer');
        Schema::dropIfExists('customer_user');
    }
}
